// src/api/admin.ts - 管理端API接口
import request from '@/utils/request';
import type {
  ResponseData,
  User,
  Project,
  Application,
  Statistics,
  ExportData
} from './adminTypes.ts';

// 用户管理API
export const userApi = {
  // 获取用户列表
  getUsers: (params?: any) => {
    return request.get<ResponseData<User[]>>('/admin/users', { params });
  },

  // 更新用户状态
  updateUserStatus: (id: number, status: string) => {
    return request.put<ResponseData<{}>>(`/admin/users/${id}/status`, { status });
  }
};

// 课题管理API
export const projectApi = {
  // 获取课题列表
  getProjects: (params?: any) => {
    return request.get<ResponseData<Project[]>>('/admin/projects', { params });
  },

  // 更新课题状态
  updateProjectStatus: (id: number, status: string) => {
    return request.put<ResponseData<{}>>(`/admin/projects/${id}/status`, { status });
  }
};

// 申请管理API
export const applicationApi = {
  // 获取申请列表
  getApplications: (params?: any) => {
    return request.get<ResponseData<Application[]>>('/admin/applications', { params });
  },

  // 更新申请状态
  updateApplicationStatus: (id: number, status: string, feedback?: string) => {
    return request.put<ResponseData<{}>>(`/admin/applications/${id}/status`, {
      status,
      feedback
    });
  }
};

// 统计分析API
export const statisticsApi = {
  // 获取统计信息
  getStatistics: () => {
    return request.get<ResponseData<Statistics>>('/admin/statistics');
  },

  // 导出统计信息
  exportStatistics: () => {
    return request.get<ResponseData<ExportData>>('/admin/statistics/export');
  }
};


import type {
  DashboardStats,
  UserChartData,
  ProjectChartData,
  ActivityItem,
  TodoItem
} from './adminTypes';

export const dashboardApi = {
  // 获取仪表盘统计数据
  getStats() {
    return request.get<{
      stats: DashboardStats;
      recentActivities: ActivityItem[];
      todos: TodoItem[];
    }>('/admin/dashboard/stats');
  },

  // 获取用户图表数据
  getUserChartData(params: { days: number }) {
    return request.get<{
      labels: string[];
      data: number[];
    }>('/admin/dashboard/user-chart', { params });
  },

  // 获取课题图表数据
  getProjectChartData() {
    return request.get<{
      series: {
        name: string;
        value: number;
      }[];
    }>('/admin/dashboard/project-chart');
  },

  // 添加待办事项
  addTodo(data: { title: string; description?: string }) {
    return request.post<TodoItem>('/admin/dashboard/todos', data);
  },

  // 更新待办事项
  updateTodo(id: number, data: { title: string; description?: string }) {
    return request.put<TodoItem>(`/admin/dashboard/todos/${id}`, data);
  },

  // 更新待办事项状态
  updateTodoStatus(id: number, data: { completed: boolean }) {
    return request.patch<TodoItem>(`/admin/dashboard/todos/${id}/status`, data);
  },

  // 删除待办事项
  deleteTodo(id: number) {
    return request.delete(`/admin/dashboard/todos/${id}`);
  }
};
